<template>
  <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
    <a-form @submit="submit" :form="form">
      <a-form-item
        :label="$t('tenantName')"
        :labelCol="{ span: 7 }"
        :wrapperCol="{ span: 10 }"
      >
        <a-input
          v-decorator="[
            'tenantName',
            { rules: [{ required: true, message: '租户名称不得为空' }] },
          ]"
          :placeholder="$t('tenantNameInput')"
        />
      </a-form-item>
      <a-form-item
        :label="$t('tenantAlias')"
        :labelCol="{ span: 7 }"
        :wrapperCol="{ span: 10 }"
      >
        <a-input
          v-decorator="[
            'tenantAlias',
            { rules: [{ required: true, message: '租户标识不得为空' }] },
          ]"
          :placeholder="$t('tenantAliasInput')"
        />
      </a-form-item>
      <a-form-item
        style="margin-top: 24px"
        :wrapperCol="{ span: 10, offset: 7 }"
      >
        <a-button type="primary" @click="submit">{{ $t("submit") }}</a-button>
      </a-form-item>
    </a-form>
  </a-card>
</template>

<script>
import { saveOrUpdateTenant, tenantDetail } from "@/services/tenant";

export default {
  name: "BasicForm",
  i18n: require("./i18n"),
  data() {
    return {
      form: this.$form.createForm(this),
      value: 1,
      productList: [],
    };
  },
  mounted() {
    this.initTenant();
  },
  methods: {
    initTenant() {
      tenantDetail(this.$route.params.id).then((rep) => {
        const data = rep.data.data;
        this.form.setFieldsValue({
          tenantName: data.tenantName,
          tenantAlias: data.tenantAlias,
        });
      });
    },
    submit() {
      this.form.validateFields((err, values) => {
        if (!err) {
          values.id = this.$route.params.id;
          saveOrUpdateTenant(values).then((rep) => {
            if (rep.data.success) {
              this.$message.success("更新设备成功");
            } else {
              this.$message.error(rep.data.msg);
            }
          });
        }
      });
    },
  },
  computed: {
    desc() {
      return this.$t("pageDesc");
    },
  },
};
</script>

<style scoped>
</style>
